Explain the Recovery model in SQL Server.
Explain the Recovery model in SQL Server
332
15-Jul-2024
Updated on 17-Jul-2024
Ashutosh Kumar Verma
17-Jul-2024SQL Server recovery model
The recovery model is a property of a SQL database. The recovery model controls the following:
SQL Server uses the model database to set the default recovery model in the newly created databases.
Let's use the current database
Create a new table
Peoplein theMyCollegeDbdatabaseNow, Insert some values into
Peopletable,View the Recovery Model
To view the recovery model of the current database in SQL server,
Also, you can see all the recovery models of all the databases in the SQL Server,
Change recovery model
To change the recovery model to another, you use the following
ALTER DATABASEstatement.Syntax-
Specify the recovery model name after the
SET RECOVERYkeyword. The recovery model can be one of these,SIMPLE,FULL, andBULK_LOGGED.The following example changes the recovery model of the
MyCollegeDbdatabase from FULL to SIMPLE.Types of Recovery Models in SQL Server
There are three type of recovery model provided by SQL server,
Simple Recovery Model
In the
SIMPLErecovery model, SQL Server deletes transaction logs from the transaction log files at every checkpoint.In the
SIMPLErecovery model, transaction logs do not store transaction records, so you cannot use advanced backup strategies to minimize data loss. This results in relatively small transaction log files.Use the
SIMPLErecovery model for databases whose data can be reloaded from other sources.Full Recovery Model
In the
FULLrecovery model allows you to restore the database at any point in time. In this recovery model, SQL Server keeps transaction logs in transaction log files until aBACKUP LOGstatement is executed means that theBACKUP LOGstatement deletes the transaction logs from the transaction log files.If you do not run the
BACKUP LOGstatement regularly, SQL Server stores all transaction information in the transaction log file until the transaction log is completed and the database is inaccessible, therefore you need to run theBACKUP LOGstatement at regular intervals to prevent the transaction log files from becoming full.BULK_LOGGED return pattern
The
BULK_LOGGEDrecovery model has almost the same behavior as theFULLrecovery model except forbulk-loggedperformance. For example, theBULK INSERTof the flat file containing the tables is summarized in transaction log files.The
BULK_LOGGEDrecovery model will never allow you to restore the database. A usefulBULK_LOGGEDrelief scenario is the following,BULK_LOGGEDFULLAlso, Read: How to create user-defined role in SQL Server Database?